module builder.Animation;
import frontend.Types;

import loader.scene.format.Hme;
import loader.scene.Node;
static import loader.scene.Animation;
import utils.Memory;
import maths.Vec;
import maths.Quat;
import maths.CoordSys;

void loadAnimation(char[] filename, char[] modelname, char[] animationname, float animationspeed){
	if(!animationCache.isCached(animationname)){
		Animation animation;
		HmeLoader hml;
		loader.scene.Animation.SkeletalAnimation skelAnim;
		hml= new HmeLoader;
		hml.load(filename);
		assert(hml !is null);
		int i;
		foreach(node; hml.scene.nodes){
			if(node.name!=modelname) continue;
			skelAnim = cast(loader.scene.Animation.SkeletalAnimation)node.animation;
			animation=new Animation(animationname, skelAnim.bones.length, animationspeed, 0);
			foreach(index, bone; skelAnim.bones){
				foreach(keyframe; bone.keyframes){
					i++;
					animation.addKeyframe(index,keyframe.time,keyframe.coordSys);
				}
			}
			break;
		}
		animationCache.addAnimation(animationname,animation);
	}
}

void loadAnimation(HmeLoader hml, char[] modelname, char[] animationname, float animationspeed){
	if(!animationCache.isCached(animationname)){
		Animation animation;
		loader.scene.Animation.SkeletalAnimation skelAnim;
		assert(hml !is null);
		int i;
		foreach(node; hml.scene.nodes){
			if(node.name!=modelname) continue;
			skelAnim = cast(loader.scene.Animation.SkeletalAnimation)node.animation;
			animation=new Animation(animationname, skelAnim.bones.length, animationspeed, 0);
			foreach(index, bone; skelAnim.bones){
				foreach(keyframe; bone.keyframes){
					i++;
					animation.addKeyframe(index,keyframe.time,keyframe.coordSys);
				}
			}
			break;
		}
		animationCache.addAnimation(animationname,animation);
	}
}